<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-radio-group v-model="queryParams.taskStat" @change="getList">
        <el-radio-button label="">全部</el-radio-button>
        <el-radio-button label="3">完成</el-radio-button>
<!--        <el-radio-button label="0">未开始</el-radio-button>-->
        <el-radio-button label="1">运行中</el-radio-button>
        <el-radio-button label="2">失败</el-radio-button>
      </el-radio-group>
      <el-form-item style="margin: 2px 0px 0px 20px;">
        <el-input
          v-model="queryParams.taskDesc"
          placeholder="搜索任务名或任务描述"
          clearable
          @keyup.enter.native="handleQuery"
        >
          <el-button slot="append" icon="el-icon-search" @click="handleQuery" ></el-button>
        </el-input>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="taskList">
      <el-table-column label="任务名" align="center" prop="taskType">
        <template slot-scope="scope">
          <el-link :underline="false" @click="handLogDetail(scope.row.id)" type="primary">{{scope.row.taskType}}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="任务ID" align="center" prop="id" />
      <el-table-column label="任务描述" align="center" prop="taskDesc" />
      <el-table-column label="任务状态" align="center">
        <template slot-scope="scope">
          <div class="badge-status-container">
            <span :class="'badge-status-do badge-status-'+scope.row.taskStat"/>
            <dict-tag :options="dict.type.kw_task_status" :value="scope.row.taskStat"/>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="执行进度" align="center">
        <template slot-scope="scope">
          {{ scope.row.finishCnt }}/{{ scope.row.totalCnt }}
        </template>
      </el-table-column>
      <el-table-column label="开始时间" align="center" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime) }}</span>
        </template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listTask } from "@/api/task/task";

export default {
  name: "Task",
  dicts:['kw_task_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 监控任务表格数据
      taskList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        taskType: null,
        taskDesc: null,
        taskStat: "",
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询监控任务列表 */
    getList() {
      this.loading = true;
      listTask(this.queryParams).then(response => {
        this.taskList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    changeState(stat) {
      this.queryParams['taskStat'] = stat;
      this.getList();
    },
    handLogDetail(logId){
      this.$router.push("/system/taskDetail/"+logId)
    }
  }
};
</script>
